package com.isoftstone.merchant.service.role.impl;


import com.isoftstone.merchant.dao.role.PRoleUserMapper;
import com.isoftstone.merchant.entity.role.PRoleUser;
import com.isoftstone.merchant.entity.role.PRoleUserKey;
import com.isoftstone.merchant.service.role.IPRoleUserService;
import com.isoftstone.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PRoleUserService implements IPRoleUserService {

    @Autowired
    PRoleUserMapper pRoleUserMapper;

    @Transactional
    public void saveUserRole(String userId, String roleId) throws Exception {
        pRoleUserMapper.deleteUserRole(userId);
        if(StringUtils.isNotBlank(roleId)){
            String[] sp = roleId.split(",");
            for (String s : sp) {
                pRoleUserMapper.saveUserRole(userId, s);
            }
        }

    }


    @Override
    public List<PRoleUser> getRolesByUserId(String userId) throws Exception{
        return pRoleUserMapper.getRolesByUserId(userId);
    }
    public void deleteUserRole(String userId) throws Exception{
        pRoleUserMapper.deleteUserRole(userId);
    }

    @Override
    public List<String> getMenuIdsByUserId(String comUserCode) throws Exception {
        return pRoleUserMapper.getMenuIdsByUserId(comUserCode);
    }

    @Override
    public String getOperatorId(int roleId) throws Exception {
        return pRoleUserMapper.getOperatorId(roleId);
    }

    @Override
    public List<PRoleUserKey> getroleIdByOperatorId(String operatorId) throws Exception {
        return pRoleUserMapper.getroleIdByOperatorId(operatorId);
    }


}
